package com.wang.mandkey.tool;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.io.IOException;

import com.wang.mandkey.utils.ProjectEnvironment;

public class CommandTool {

	static Robot robot = null;
	static Runtime runtime;

	static {
		try {
			robot = new Robot();
			runtime = Runtime.getRuntime();
		} catch (AWTException e) {
			e.printStackTrace();
		}
	}

	public static void exeCcommand(String command) {
		System.out.println("command:" + command);

		if (STRING_COMMAND_ENTER.equals(command)) {// 回车键
			robot.keyPress(KeyEvent.VK_ENTER);
			robot.keyRelease(KeyEvent.VK_ENTER);
		} else if (STRING_COMMAND_CLOSE.equals(command)) {// alt+f4

			robot.keyPress(KeyEvent.VK_ALT);
			robot.keyPress(KeyEvent.VK_F4);

			robot.keyRelease(KeyEvent.VK_F4);
			robot.keyRelease(KeyEvent.VK_ALT);

		} else if (STRING_COMMAND_STOP_IMG_SEND.equals(command)) {// 停止发送图片
			ProjectEnvironment.BOOLEAN_STOP_SEND_IMG = true;
			System.out.println("停止发送图片");
		} else if (STRING_OMMMAND_START_IMG_SEND.equals(command)) {// 开始发送图片
			ProjectEnvironment.BOOLEAN_STOP_SEND_IMG = false;
		} else if (STRING_COMMAND_RIGHT_CLICK.equals(command)) {

			robot.mousePress(InputEvent.BUTTON3_MASK);
			robot.mouseRelease(InputEvent.BUTTON3_MASK);
		} else if (STRING_COMMAND_PPT_F5.equals(command)) {

			robot.keyPress(KeyEvent.VK_F5);
			robot.keyRelease(KeyEvent.VK_F5);

		} else if (STRING_COMMAND_PPT_ESC.equals(command)) {

			robot.keyPress(KeyEvent.VK_ESCAPE);
			robot.keyRelease(KeyEvent.VK_ESCAPE);
		} else if (STRING_COMMAND_PPT_PRE.equals(command)) {
			robot.keyPress(KeyEvent.VK_LEFT);
			robot.keyRelease(KeyEvent.VK_LEFT);
		} else if (STRING_COMMAND_PPT_NEX.equals(command)) {
			robot.keyPress(KeyEvent.VK_RIGHT);
			robot.keyRelease(KeyEvent.VK_RIGHT);
		} else if (STRING_COMMAND_PPT_UP.equals(command)) {
			robot.keyPress(KeyEvent.VK_UP);
			robot.keyRelease(KeyEvent.VK_UP);
		} else if (STRING_COMMAND_PPT_DOWN.equals(command)) {
			robot.keyPress(KeyEvent.VK_DOWN);
			robot.keyRelease(KeyEvent.VK_DOWN);
		} else if (STRING_COMMAND_LOCK_SCREEN.equals(command)) {
			// robot.keyPress((int) KeyEvent.WINDOW_EVENT_MASK);
			// robot.keyPress(KeyEvent.VK_L);
			// robot.keyRelease(KeyEvent.VK_L);
			// robot.keyRelease((int) KeyEvent.WINDOW_EVENT_MASK);
		} else if (MOVE_MOUSE.equals(command)) {
			System.out.println("command:" + command);
		} else if (CLICK.endsWith(command)) {
			System.out.println("click:" + command);
		}

	}

	public static void execDos(String dos) {

		try {
			runtime.exec(dos);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static final String CLICK = "click";
	public static final String MOVE_MOUSE = "moveMouse";
	public static final String STRING_COMMAND_ENTER = "enter";
	public static String STRING_COMMAND_RIGHT_CLICK = "right_click";
	public static String STRING_COMMAND_CLOSE = "close_current";
	public static String STRING_COMMAND_STOP_IMG_SEND = "stop_send_img";
	public static String STRING_OMMMAND_START_IMG_SEND = "start_send_img";

	public static String STRING_COMMAND_PPT_F5 = "F5";
	public static String STRING_COMMAND_PPT_ESC = "ESC";
	public static String STRING_COMMAND_PPT_PRE = "pre";
	public static String STRING_COMMAND_PPT_NEX = "nex";

	public static String STRING_COMMAND_PPT_UP = "up";
	public static String STRING_COMMAND_PPT_DOWN = "down";
	public static String STRING_COMMAND_LOCK_SCREEN = "lock_screen";
}
